package com.supreme.cacheserver.controller;

import com.supreme.cacheserver.service.TestService;
import com.supreme.commonboot.utils.AjaxResp;
import com.supreme.commonentity.mysql.primary.MBTest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value = "cache")
public class CacheController {

    @Resource
    private TestService testService;

    @GetMapping(value = "tests/all")
    public AjaxResp searchTest() {
        final List<MBTest> testList = testService.selectCacheTest();
        return new AjaxResp(testList);
    }

    @GetMapping(value = "tests/{testId}")
    public AjaxResp searchTestOne(@PathVariable(value = "testId") Long testId) {
        final MBTest testOne = testService.selectCacheTestOne(testId);
        return new AjaxResp(testOne);
    }

    @GetMapping(value = "tests")
    public AjaxResp searchTestList() {
        final List<MBTest> testList = testService.selectCacheTestList();
        return new AjaxResp(testList);
    }

    @GetMapping(value = "tests/cache/{testId}")
    public AjaxResp searchCacheTestOne(@PathVariable(value = "testId") Long testId) {
        final MBTest testOne = testService.selectCacheableTestOne(testId);
        return new AjaxResp(testOne);
    }

    @GetMapping(value = "tests/cache")
    public AjaxResp searchCacheTestList() {
        final List<MBTest> testList = testService.selectCacheableTestList();
        return new AjaxResp(testList);
    }

    @PostMapping(value = "tests/cache")
    public AjaxResp createCacheTestList(@RequestBody MBTest test) {
        final int result = testService.createCacheableTestOne(test);
        return new AjaxResp(result);
    }

    @PutMapping(value = "tests/cache")
    public AjaxResp updateCacheTestList(@RequestBody MBTest test) {
        final int result = testService.updateCacheableTestOne(test);
        return new AjaxResp(result);
    }

    @DeleteMapping(value = "tests/cache/{testId}")
    public AjaxResp deleteCacheTestList(@PathVariable(value = "testId") Long testId) {
        final int result = testService.deleteCacheableTestOne(testId);
        return new AjaxResp(result);
    }
}
